#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        v.push_back({ a,b });
    }

    sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.first < b.first;
        });

    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0; i < n; i++)
    {
        if (pq.empty() || pq.top() >= v[i].first)    pq.push(v[i].second);
        else
        {
            pq.pop();
            pq.push(v[i].second);
        }
    }

    cout << pq.size() << endl;
    return 0;
}